/**
 * 
 */
package com.yinhai.activity;

import java.util.HashMap;
import java.util.Map;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.ImageButton;


/**
 * @author Juyon
 * 
 */
public class NewsListFragment extends Fragment {
	private WebView webview; 
	private ImageButton news_btn;
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.main_news, null);
		 //实例化WebView对象  
        webview = (WebView)view.findViewById(R.id.newswebview);  
        //设置WebView属性，能够执行Javascript脚本  
        webview.getSettings().setJavaScriptEnabled(true);  
        //加载需要显示的网页  
        webview.loadUrl("file:///android_asset/main.htm"); 
        news_btn = (ImageButton)view.findViewById(R.id.news_btn);
        news_btn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
			    if(webview.canGoBack()){  
			    	//是否还能继续返回，能继续返回执行
			    	webview.goBack();
                }else{  
                	Map<String, String> map = new HashMap<String, String>();
    				FragmentTransaction transaction = getActivity().getSupportFragmentManager()
    						.beginTransaction();
    				Fragment fragment = new AppFragment();
    				Bundle bundle = new Bundle();
    				bundle.putInt("id", 22);
    				fragment.setArguments(bundle);
    				transaction.replace(R.id.container, fragment);
    				transaction.commit();
                }  
			}
		});
		return view;
	}
	
	 
  //设置回退  
  //覆盖Activity类的onKeyDown(int keyCoder,KeyEvent event)方法  
  public boolean onKeyDown(int keyCode, KeyEvent event) {  
      if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) {  
          webview.goBack(); //goBack()表示返回WebView的上一页面  
          return true;  
      }  
      return false;  
	}
}
